/**   
 * @title Launcher.java 
 * @package com.hopechart.importutil.app 
 * @description TODO 
 * @author daijiang@hopechart.com
 * @date 2016年1月13日 上午8:46:13 
 * @version v1.0.0
 * @copyright 杭州鸿泉数字设备有限公司
 */
package com.hopechart.importutil.app;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.hopechart.importutil.exception.BusinessException;
import com.hopechart.importutil.model.service.impl.TemplateServiceImpl;

/**
 * @className Launcher
 * @description TODO
 * @author daijiang@hopechart.com
 * @date 2016年1月13日 上午8:46:13
 * 
 */
public class Launcher {

    private static ClassPathXmlApplicationContext context = null;

    private static final Logger log = LoggerFactory.getLogger(Launcher.class);
    
    public static void main(String[] args) {
        try {
            log.info("容器启动中......");
            context = new ClassPathXmlApplicationContext("classpath:root-context.xml");
            log.info("容器已启动......");
            
            log.info("导入任务开始执行......");
            long startTime = System.currentTimeMillis();
            insert(context.getBean("templateServiceImpl", TemplateServiceImpl.class));
            long endTime = System.currentTimeMillis();
            log.info("导入任务执行完成，耗时" + ((endTime - startTime) / 1000) + "秒......");
            
            while(System.in.read() != -1) {
                
            }
        } catch (BusinessException e) {
            log.error("应用启动异常, " + e.getMessage());
            if (null != context) {
                context.close();
            }
        } catch (Exception e) {
            log.error("应用启动异常, ！" + e.getMessage(), e);
        } finally {
            if (null != context) {
                context.close();
            }
        }
    }

    private static void insert(TemplateServiceImpl codeTableService) throws BusinessException{
        codeTableService.batchInsert();
    }
}
